<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="../../__/import.js"></script>
<title>编辑功能</title>
<style>
</style>
</head>
<body>
	<div id="vm" class="vm-virtual" v-cloak>
		<form is="el-form" :model="form" ref="form" style="width: 500px;" size="mini" label-width="80px">
			<div is="el-form-item" label="上级">
				<input is="el-input" v-model="form.parentNamePath" size="small" disabled="disabled" readonly="readonly">
			</div>
			<div is="el-form-item" label="类别" :required="true">
				<div is="el-radio-group" v-model="form.type">
					<div is="el-radio" :label="2">目录</div>
					<div is="el-radio" :label="3">菜单</div>
					<div is="el-radio" :label="4">按钮</div>
				</div>
			</div>
			<div is="el-form-item" label="名称" :required="true">
				<input is="el-input" v-model="form.name" size="small" autocomplete="off" maxlength="20" show-word-limit>
			</div>
			<div is="el-form-item" label="编码" :required="true">
				<input is="el-input" v-model="form.code" size="small" autocomplete="off" maxlength="20" show-word-limit>
			</div>
			<div is="el-form-item" label="访问路径">
				<input is="el-input" v-model="form.path" size="small" autocomplete="off" maxlength="500" show-word-limit>
			</div>
			<div is="el-form-item" label="图标">
				<input is="el-input" v-model="form.icon" size="small" autocomplete="off" maxlength="20" show-word-limit>
			</div>
			<div is="el-form-item" label="备注">
				<input is="el-input" type="textarea" v-model="form.remark" maxlength="200" show-word-limit>
			</div>
			<div is="el-form-item" label="排序号">
				<input is="el-input-number" v-model.number="form.ordinal" :precision="0" :step="1" :max="99999" min="0" autocomplete="off" controls-position="right" style="width: 120px;">
			</div>
			<div is="el-form-item" align="center" style="margin-top: 20px;">
				<button is="el-button" type="success" @click="confirm()">确定</button>
				<button is="el-button" @click="cancel()">取消</button>
			</div>
		</form>
	</div>
	<script>
		new Vue({
			el : '#vm',
			data : {
				form : {
					id : '',
					parentId : '0',
					parentNamePath : '',
					type : '',
					code : '',
					name : '',
					path : '',
					icon : '',
					remark : '',
					ordinal : 1000
				}
			},
			created : function() {
				__.$vm = this;
			},
			mounted : function() {
				var vm = this;
				var search = __.decodeUrlParams();
				vm.form.parentId = search.parentId || '0';
				vm.form.type = (search.type | 0) || 3;
				if (!__.isEmpty(search.id)) {
					__.api('POST', '/rest/permission/getById', {
						id : search.id
					}, function(result) {
						if (__.err(result)) {
							__.message({
								message : result.message,
								type : 'warning'
							});
							return;
						}
						vm.form = result.data;
					});
					return;
				}
				if (vm.form.parentId == '0') {
					vm.form.parentNamePath = '';
					return;
				}
				__.api('POST', '/rest/permission/getNamePathById', {
					id : search.parentId
				}, function(result) {
					if (__.err(result)) {
						__.message({
							message : result.message,
							type : 'warning'
						});
						return;
					}
					vm.form.parentNamePath = result.data;
				});
			},
			methods : {
				confirm : function() {
					var vm = this;
					var params = {};

					params.id = vm.form.id;
					params.parentId = __.trim(vm.form.parentId);
					params.type = __.trim(vm.form.type);
					params.code = __.trim(vm.form.code);
					params.name = __.trim(vm.form.name);
					params.path = __.trim(vm.form.path);
					params.icon = __.trim(vm.form.icon);
					params.remark = __.trim(vm.form.remark);
					params.ordinal = vm.form.ordinal;
					if (__.isEmpty(params.name)) {
						__.message({
							message : '请输入功能名称！',
							type : 'warning'
						});
						return;
					}
					if (__.isEmpty(params.code)) {
						__.message({
							message : '请输入功能编码！',
							type : 'warning'
						});
						return;
					}
					var path = __.isEmpty(params.id) ? '/rest/permission/save' : '/rest/permission/update';
					__.mask();
					__.api('POST', path, params, function(result) {
						__.unmask();
						if (__.err(result)) {
							__.message({
								message : result.message,
								type : 'warning'
							});
						} else {
							__.message({
								message : '保存成功！',
								type : 'info'
							});
							__.dialog.close();
						}
					});
				},
				cancel : function() {
					__.dialog.close();
				}
			}
		})
	</script>
</body>
</html>